package com.fairytask.ui.item
{
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.button.Button;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.Filter;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.managers.BindManager;
	import com.fairytask.managers.ResManager;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.tools.MoneyTools;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	
	
	/**
	 *显示充值回馈大礼包的类型子项 
	 * @author yangj
	 * 
	 */	
	public class TopUpRewardItem extends BaseItem
	{
		
		private var _type			:int;									//子项的类型
		private var _bg			:MovieClip;								//子项的背景
		private var _itemLabel		:Label	=	new Label();				//子项的top的文字
		private var _icon			:Clip   = 	new Clip();					//需要显示的图片
		private var _numLabel		:Label	=	new Label();				//右下方显示的仙玉数量
		public var _button		:Button;								//领取按钮
		private var _silver		:int;									//玩家充值的仙玉
		private var _needSilver	:int;									//获取奖励所需的仙玉
		private var _typeId		:String;
		
		protected var bindManager	:BindManager	=	BindManager.instance;
		
		public function TopUpRewardItem(type:int,typeId:String)
		{
			super();
			_type = type;
			_typeId = typeId;
			_needSilver = int(StaticIni.getIniVar(_typeId,"GoldAmount"));
			init();
			initEvent();
		}
		
		/**
		 *初始化界面 
		 * 
		 */		
		private function init():void
		{
			_bg = ResManager.newResClass("CustSkin_017") as MovieClip;
			_bg.width = 90;
			_bg.height = 120;
			addChild(_bg);
			
			_icon.source	=	ResConfig.iconPath + StaticIni.getIniVar(_typeId,"EachPrize")+".jpg";
			_icon.x = 20;
			_icon.y = 25;
			addChild(_icon);
			
			_itemLabel.htmlStr = StaticIni.getSwfLangStrVar("1000000623",[MoneyTools.setMoney(_needSilver)]);
			_itemLabel.x = (this.width - _itemLabel.width)/2;
			_itemLabel.y = 5;
			addChild(_itemLabel);
			
			
			
			_numLabel.y = 58;
			addChild(_numLabel);
			
			_button = new Button("",50,25,"button_034");
			_button.label = StaticIni.getSwfLangStr("1000000626");			//按钮先默认为领取，同事不可点击状态
			_button.enabled = false;
			_button.x = 20;
			_button.y = 85;
			addChild(_button);
			
			

			
		}
		
		/**
		 * 添加事件 
		 * 
		 */		
		private function initEvent():void
		{
			//bindManager.BindProp(_player.data,"GoldExp",this,"pGoldExp");
			_button.addEventListener(MouseEvent.CLICK,sendMessage);
		}
		
		private function sendMessage(evt:MouseEvent):void
		{
			//NetMgr.sendCustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AWARD_GET,_type);
			trace("发送领取奖励的消息了");
		}
		
		/**
		 *动态修改充值的仙玉 
		 * 
		 */		
		public function set pGoldExp(val:int):void
		{
			_silver = val;
			_numLabel.htmlStr = "";
			if(_silver>=_needSilver)
			{
				_numLabel.htmlStr = StaticIni.getSwfLangStrVar("1000000034",[MoneyTools.setMoney(val)])+"/"+StaticIni.getSwfLangStrVar("1000000033",[MoneyTools.setMoney(_needSilver)]);
				_numLabel.x = 76 - _numLabel.width -2;
			}
			else
			{
				_numLabel.htmlStr = StaticIni.getSwfLangStrVar("1000000037",[MoneyTools.setMoney(val)])+"/"+StaticIni.getSwfLangStrVar("1000000033",[MoneyTools.setMoney(_needSilver)]);
				_numLabel.x = 70 - _numLabel.width +2;
			}
		}
		
		/**
		 *添加选中 
		 * @param evt
		 * 
		 */		
		public function addSelect():void
		{
			_bg.filters = [Filter.YELLOW_GLOW];
		}
		
		public function clearSelect():void
		{
			_bg.filters = null;	
		}
		
		/**
		 *修改按钮的显示的状态 
		 * @param flag
		 * 
		 */		
		public function set buttonState(flag:Boolean):void
		{
			_button.enabled  = flag;	
		}
		
		/**
		 *设置按钮的文字 
		 * 
		 */		
		public function set buttonLabel(val:String):void
		{
			_button.label = val;
		}
		
		
		public function get typeId():String
		{
			return _typeId;
		}
		
		public function set typeId(typeId:String):void
		{
			_typeId = typeId;
		}
		
		
		
		
		
		
		
		public function get type():int
		{
			return _type;
		}
		
		public function set type(type:int):void
		{
			_type = type;
		}
	}
}